#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<char>A;
	queue<int>B;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		char ch;
		cin >> ch;
		A.push(ch);
	}
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		B.push(m);
	}
	int a1=0, a2=0, a3=0;
	int b1=0, b2=0, b3=0;
	for (int i = 0; i < n; i++) {
		char ch = A.front();
		int m = B.front();
		if (ch == 'A') {
			a1 += m;
			b1++;
		}
		else if (ch == 'B') {
			a2 += m;
			b2++;
		}
		else {
			a3 += m;
			b3++;
		}
		A.pop();
		B.pop();
	}
	cout << a1 / b1 << endl;
	cout << a2 / b2 << endl;
	cout << a3 / b3 << endl;
	return 0;
}